#include <stdio.h>

#define StackSize 100
typedef char DataType;
typedef struct{
    DataType data[StackSize];
    int top;
}SeqStack;

//置空栈
void InitStack(SeqStack *S)
{
    S->top = -1;
}

//判栈空
int StackEmpty(SeqStack *S)
{
    return S->top == -1;
}

//判栈满
int StackFull(SeqStack *S)
{
    return S->top == StackSize-1;
}

//进栈
void Push(SeqStack *S, DataType x)
{
    if(StackFull(S)){
        printf("Stack overflow");
    }else{
        S->top = S->top + 1;
        S->data[S->top] = x;
    }
}

//退栈
DataType Pop(SeqStack *S)
{
    DataType x;
    if(StackEmpty(S)){
        printf("Stack empty");
        exit(0);
    }else{
        x = S->data[S->top];
        S->top--;
        return x;
    }
}

//取栈顶元素（不改变栈顶指针）
DataType GetPop(SeqStack *S)
{
    if(StackEmpty(S)){
        printf("Stack empty");
        exit(0);
    }else{
        return S->data[S->top];
    }
}

/**
 * 检查一个字符串或一个表达式中的括号是否相匹配 例如：a+(b*c)+(d+(e/f))
 * @return
 */
int Expr()
{
    SeqStack S;
    DataType ch;
    InitStack(&S);
    ch = getchar();
    while(ch != '\n'){
        if(ch == '('){
            Push(&S, ch);
        }else if(ch == ')'){
            if(StackEmpty(&S)){
                return 0;
            }else{
                Pop(&S);
            }
        }
        ch = getchar();
    }
    if(StackEmpty(&S)){
        return 1;
    }else{
        return 0;
    }
}
/**
 * 进制转换 n=(n div d)*d+n mod d
 * 例如(1348)10=(2504)8
 */
void conversion(int n, int d)
{
    SeqStack S;
    InitStack(&S);
    while(n != 0){
        Push(&S, n%d);
        n = n/d;
    }

    while(!StackEmpty(&S)){
        printf("%d", Pop(&S));
    }
}

int main()
{
    int res;
//    SeqStack S;
//    InitStack(&S);
////    int a = StackFull(&S);
////    printf("%d", a);
//    Push(&S, 'a');
//    Push(&S, 'b');
//    Push(&S, 'c');
//    putchar(GetPop(&S));
//    putchar(Pop(&S));
//    res = Expr();
//    printf("%d", res);
    conversion(1348, 8);
    return 0;
}